package org.qf.web;
import org.qf.pojo.SmbmsUser;
import org.qf.service.SmbmsUserService;
import org.qf.service.impl.SmbmsUserServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @author young
 * @create 2021-01-13-16:59
 * @description
 */
@WebServlet(value = "/userView")
public class ShowUserServlet extends HttpServlet {
    @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
        {
            this.doPost(req, resp);
        }
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
        {
//        从页面获取ID
         String id=req.getParameter("id");
         Long ids=0L; if(id != null)
         { ids=Long.parseLong(id); }
//         调用业务层接口
         SmbmsUserService smbmsUserService=new SmbmsUserServiceImpl();
         try {SmbmsUser smbmsUser = smbmsUserService.queryUserById(ids);
         if(null != smbmsUser)
         {
//         把对象放在request作用域中
         req.setAttribute("user",smbmsUser);
         req.getRequestDispatcher("userView.jsp").forward(req,resp);
         }
         } catch (Exception e)
         { e.printStackTrace();
    } } }